<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
     <meta name='viewport' content='width=device-width, initial-scale=1.0'>
     <title>箭头函数</title>
     <link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css'>
     <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js'></script>
</head>
<body>
     <pre>
        <code style='max-height: 400px;'>
            function sun (n,m){
                return n + m
            }
    
            console.log(sun(1,2));
    
            // 箭头函数
            // let _sun = (n,m) => {
            //     return n + m
            // }
    
            // 写法2 ==> 如果函数体中只有一行return 可以省略return和大括号 一行搞定
            let _sun = (n,m) => n + m
            console.log(_sun(1,2));
    
            // 非箭头函数
            let fn = function(m){
                return function(n){
                    return m + n
                }
            }
    
            // 箭头函数
            console.log(fn(1)(2));
            let _fn = m => n => m + n
            console.log(_fn(1)(2));
    
            // 形参赋值默认值
            let _sum = (n = 1,m = 0) => n + m
            console.log(_sum());
            console.log(_sum(1,2)); 
    
            // 箭头函数中没有arguments 但是给我们提供了一个比arguments还厉害的 ==> 剩余运算符 ...arg || ...[val] ==> console.log(arg || [val]) ==> [1,2,3,4] 数组 ==> 不是类数组
            let sum = (...arg) => {
                console.log(arg);
                let result = 0 
                arg.forEach(item => {
                    result += item
                })
                return result
            }
    
            console.log(sum(1,2,3,5,6,8,9,4,2));           
        </code>
     </pre>
     <script> hljs.highlightAll(); </script>
     <script>
        function sun (n,m){
            return n + m
        }

        console.log(sun(1,2));

        // 箭头函数
        // let _sun = (n,m) => {
        //     return n + m
        // }

        // 写法2 ==> 如果函数体中只有一行return 可以省略return和大括号 一行搞定
        let _sun = (n,m) => n + m
        console.log(_sun(1,2));

        // 非箭头函数
        let fn = function(m){
            return function(n){
                return m + n
            }
        }

        // 箭头函数
        console.log(fn(1)(2));
        let _fn = m => n => m + n
        console.log(_fn(1)(2));

        // 形参赋值默认值
        let _sum = (n = 1,m = 0) => n + m
        console.log(_sum());
        console.log(_sum(1,2)); 

        // 箭头函数中没有arguments 但是给我们提供了一个比arguments还厉害的 ==> 剩余运算符 ...arg || ...[val] ==> console.log(arg || [val]) ==> [1,2,3,4] 数组 ==> 不是类数组
        let sum = (...arg) => {
            console.log(arg);
            let result = 0 
            arg.forEach(item => {
                result += item
            })
            return result
        }

        console.log(sum(1,2,3,5,6,8,9,4,2));
     </script>
</body>
</html>